//
//  TradeListFilterVM.swift
//  kxf
//
//  Created by Mac on 2024/3/20.
//

import Foundation
import UIKit

class TradeListFilterVM: UIView {
    
    let selfHeight = kFitWidth(48)
    
    var tapBlock:(()->())?
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var titleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: .zero)
        vm.titleLabel.text = "筛选"
        
        return vm
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        lab.text = "\(Date().todayDate)  -  \(Date().todayDate)"
        
        return lab
    }()
    lazy var arrowImg : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "arrow_img_down")
        
        return img
    }()
    lazy var tapView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .clear
        vi.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapAction))
        vi.addGestureRecognizer(tap)
        
        return vi
    }()
}

extension TradeListFilterVM{
    @objc func tapAction() {
        if self.tapBlock != nil{
            self.tapBlock!()
        }
    }
}

extension TradeListFilterVM{
    func initUI() {
        addSubview(titleVm)
        addSubview(timeLabel)
        addSubview(arrowImg)
        addSubview(tapView)
        
        setConstrait()
    }
    func setConstrait() {
        arrowImg.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-12))
            make.centerY.lessThanOrEqualToSuperview()
            make.width.height.equalTo(kFitWidth(22))
        }
        timeLabel.snp.makeConstraints { make in
            make.right.equalTo(arrowImg.snp.left).offset(kFitWidth(-2))
            make.top.height.equalToSuperview()
        }
        tapView.snp.makeConstraints { make in
            make.top.height.right.equalToSuperview()
            make.left.equalTo(timeLabel)
        }
    }
}
